﻿using System;
using System.Collections.Generic;
using FunctionalCLR.Core;
using NUnit.Framework;
using Zove.Query;

namespace Zove.Test {
    [TestFixture]
    public class QueryTests {
        [Test]
        public void TestParse() {
            QueryParser p = new QueryParser(
                "select hello, kitty from world where name='me', addr='java'");
            Query.Query d = p.Parse();
        }

        [Test]
        public void TestReplace() {
            Assert.AreEqual(
                "t.c+hello",
                Utils.ReplaceString("c", "hello", "t.c+c"));
        }

        public List<QueryResult> Query(string query) {
            QueryManager qm = new QueryManager();
            Query.Query q = qm.CreateQuery(query);
            List<QueryResult> results = q.Run();

            return results;
        }

        [Test]
        public void TestQueryOfCircle() {
            List<QueryResult> results = this.Query(
                "select * from circle where c=10;");

            //Assert.AreEqual("area", results[0].Item);
            //Assert.AreEqual("314.15926", results[0].Value);

            DisplayResults(results);
        }

        [Test]
        public void TestBooleanQuery() {
            List<QueryResult> results = this.Query(
                "select area > 0 from circle where r=10;");

            Assert.AreEqual("area>0", results[0].Item);
            Assert.AreEqual("True", results[0].Value);
        }

        [Test]
        public void TestEllipse() {
            List<QueryResult> results = this.Query(
                "select * from ellipse where c=10;");

            //Assert.AreEqual("area", results[0].Item);
            //Assert.AreEqual("282.743334", results[0].Value);

            DisplayResults(results);
        }
        
        [Test]
        public void TestTrapzoid() {
            List<QueryResult> results = this.Query(
                "select area from trapezoid where top=5, bottom=9, A=PI/3, B=PI/6;");

            Assert.AreEqual("area", results[0].Item);
            Assert.AreEqual("282.743334", results[0].Value);
        }

        [Test]
        public void TestCone() {
            List<QueryResult> results = this.Query(
                "select * from cone where height=9, bottom.c=10;");

            DisplayResults(results);
        }

        [Test]
        public void TestCylinder() {
            List<QueryResult> results = this.Query(
                "select * from cylinder where height=9, bottom.c=10;");

            DisplayResults(results);
        }

        public void DisplayResults(List<QueryResult> results) {
            foreach (QueryResult result in results) {
                Console.WriteLine("{0} = {1}", result.Item, result.Value);
            }
        }

        [Test]
        public void TestPlanar() {
            ZoveQuery.Main(
                new string[] 
                { @"C:\Documents and Settings\samh\My Documents\Visual Studio 2008\Projects\Zove\Zove.Test\bin\Debug\Query\Planar.zql" });
        }

        [Test]
        public void TestSpatial() {
            ZoveQuery.Main(
                new string[] { 
            @"C:\Documents and Settings\samh\My Documents\Visual Studio 2008\Projects\Zove\Zove.Test\Files\Query\Spatial.zql" });
        }

        [Test]
        public void TestSphereCone() {
            ZoveQuery.Main(
                new String[] {
                @"C:\Program Files\Zove\Models\Demonstrations\Geometry\Optimization\Sphere Cone\SphereCone.zql"});
        }
    }
}
